import {
    Autowired,
    Controller,
    GetMapping,
    KoaContext,
    PostMapping,
    RequestMapping,
    RequestParam
} from '@framework/decorator/index'
import SystemService from "@app/service/SystemService";
import User from "@app/entity/User";
import {Context} from "koa";
import {ParsedUrlQuery} from "querystring";
import KoaBootLogger from "@framework/web/KoaBootLogger";
import KoaBootUtil from "@framework/util/KoaBootUtil";
import KoaBootRedis from "@framework/web/KoaBootRedis";

@Controller
@RequestMapping("/admin")
class SystemController {

    @Autowired
    private logger: KoaBootLogger;

    @Autowired
    private systemService: SystemService;

    @Autowired
    private systemService2: SystemService;

    @Autowired
    private SystemService: SystemController;

    @GetMapping("/test")
    public async test1(@KoaContext ctx: Context, @RequestParam("id") id: number): Promise<void> {
        const bean = KoaBootUtil.getBean(KoaBootRedis.name) as KoaBootRedis;
        this.logger.info("bean", bean)
        this.logger.info("test")
        const user = new User();
        user.age = 18;
        user.name = "张三";
        ctx.body = user;
    }

    @GetMapping("/test/return")
    public async test2(@KoaContext ctx: Context): Promise<ParsedUrlQuery> {
        return ctx.request.query;
    }

    @PostMapping("/test")
    public async test3(@RequestParam("name") name: string): Promise<User> {
        const user = new User();
        return user;
    }
}

export default SystemController;